<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="format-detection" content="telephone=no">
		<link href="{$Think.config.RESOURCEURL}wx_assets/css/common.css{$Think.config.RESOURCE_VER}" rel="stylesheet">
		<link rel="stylesheet" href="{$Think.config.RESOURCEURL}wx_assets/css/product/search.css{$Think.config.RESOURCE_VER}" />
		<!--<script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/remWebApp.js{$Think.config.RESOURCE_VER}"></script>-->
		<script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/zepto.min.js{$Think.config.RESOURCE_VER}"></script>
		<script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/zepto.alert.js{$Think.config.RESOURCE_VER}"></script>
		<script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/util.js{$Think.config.RESOURCE_VER}"></script>
		<title>搜索</title>
	</head>
	
	<body>
		<form>
			<div class="order-search">
				<div>
				<i class="searchicon">&#xe61a;</i>
				<input autocomplete="off"  type="search" id="search" placeholder="输入商品名">
				</div>
				<a onclick="submitSearch()">搜索</a>
			</div>
		</form>
		<div class="hotSearch">
			<volist name="searchHistoryList" id="l">
			<a class="border" style="position:relative;" onclick="goResult('{$l.searchHistory}')" >{$l.searchHistory}</a>
			</volist>
		</div>
		<empty name="userHistoryList">
		<else />
		<div class="historyList">
			<h2>历史记录：</h2>
			<ul>
				<volist name="userHistoryList" id='h'>
					<li>
						<a  style="color: #999;display: block;position: relative;" onclick="goResult('{$h.searchHistory}')" >{$h.searchHistory}</a>
					</li>
				</volist>
			</ul>
		</div>
		<a onclick="deletedHis()" class="deleted">删除历史记录</a>
		</empty>
	</body>
	<script>
	    var baseUrl = '{$Think.config.SERVER_HOST}';
	    function goResult(keyword){
	    	var params={
				"keyword":keyword,
				"qId":hrefParamsArray["qId"]?hrefParamsArray["qId"]:'',
				"miUId":hrefParamsArray["miUId"]?hrefParamsArray["miUId"]:''
			}
		    params=encodeURIComponent(JSON.stringify(params));
	    	window.location.href=baseUrl+"call.html?userName=&customerId={$customerId}&module=product&method=searchProduct&params="+params;
	    }
		var hrefParamsArray = GetSessionIdFromHref(window.location.search);
		function GetSessionIdFromHref(search){
		　　	var args = search.substring(1); 
		　　	var retval = new Array(); 
			args = args.split("&"); 
				for(var i = 0; i < args.length; i ++){ 
					str = args[i]; 
					var arg = str.split("="); 
					if(arg.length <= 1) continue; 
					
					if(arg[0] == 'params') {
						var params = decodeURIComponent(arg[1]);
						var obj = eval('(' + params + ')');
						if (obj.keyword != undefined) {
							retval["keyword"] = obj.keyword;
						}
						if (obj.qId != undefined) {
							retval["qId"] = obj.qId;
						}
						if (obj.miUId != undefined) {
							retval["miUId"] = obj.miUId;
						}
						retval["id"] = obj.id;
					} else if(arg[0] == 'customerId') {
						retval["customerId"] = arg[1]; 
					}else if(arg[0] == 'userName'){
						retval["userName"] = arg[1]; 
					} else if(arg[0] == 'method') {
						retval["method"] = arg[1];
					} else if (arg[0] == 'module') {
						retval["module"] = arg[1];
					}
				} 
				
				if (retval["start"] == undefined) {
					retval["start"] = 0;
				}
				return retval; 
		}
		function search(event){
			var v=document.getElementById('search').value;
			var e = event||window.event; 
				if(e.keyCode=='13')
				{
					
					e.preventDefault();
					if(v)
					{
						var qId=hrefParamsArray["qId"]?hrefParamsArray["qId"]:'',
							miUId=hrefParamsArray["miUId"]?hrefParamsArray["miUId"]:'';
					 	window.location.href='call.html?customerId={$customerId}&module=product&method=searchProduct&params=%7B%22keyword%22:%22'+v+'%22,%22qId%22:%22'+qId+'%22,%22miUId%22:%22'+miUId+'%22%7D';
					}
					else
					{
						alert('请输入关键词搜索~')
					}
				}
		}
		
		function submitSearch(){
			var v=document.getElementById('search').value;
			var qId=hrefParamsArray["qId"]?hrefParamsArray["qId"]:'',
				miUId=hrefParamsArray["miUId"]?hrefParamsArray["miUId"]:'';
			window.location.href='call.html?customerId={$customerId}&module=product&method=searchProduct&params=%7B%22keyword%22:%22'+v+'%22,%22qId%22:%22'+qId+'%22,%22miUId%22:%22'+miUId+'%22%7D';
		}
		
		function deletedHis(){
			$.ajax({
				url:'call.json?customerId={$customerId}&module=product&method=delSearchHistory',
				dataType:'json',
				type:'GET',
				beforeSend:function(){
					$.util.pageLoading.show('删除记录中..');
				},
				success:function(){
					$.util.pageLoading.hide();
					$.util.alert('删除完成');
					window.location.reload();
				}
			})
		}
		var f = document.getElementById('search');
        f.addEventListener('keypress', search);
        $(function(){
			f.focus();
		})
	</script>
</html>
